package Experiment2;

import java.util.ArrayList;
import java.util.List;
public class Student {
    private String studentId;
    private String name;
    private String gender;
    private List<Course> selectedCourses = new ArrayList<>();

    public Student(String studentId, String name, String gender) {
        this.studentId = studentId;
        this.name = name;
        this.gender = gender;
    }

    public void selectCourse(Course course) {
        selectedCourses.add(course);
        System.out.println("学生 " + name + " 选择课程：" + course.getCourseName());
    }

    public void dropCourse(Course course) {
        if (selectedCourses.remove(course)) {
            System.out.println("学生 " + name + " 退选课程：" + course.getCourseName());
        } else {
            System.out.println("学生 " + name + " 未选该课程，无法退课！");
        }
    }

    public void printSchedule() {
        System.out.println("=== 学生 " + name + " 的课表 ===");
        System.out.println("课程编号\t课程名称\t上课地点\t上课时间\t授课教师");
        for (Course course : selectedCourses) {
            System.out.println(course.getCourseId() + "\t" + course.getCourseName() + "\t" +
                    course.getLocation() + "\t" + course.getTime() + "\t" +
                    getTeacherNameByCourse(course));
        }
    }

    private String getTeacherNameByCourse(Course course) {
        return "教师" + course.getTeacherId().substring(2);
    }

    // Getter方法
    public String getStudentId() { return studentId; }
    public String getName() { return name; }
}

